import axios from 'axios';
import query from 'query-string';

const BASE_URL = '/promotion/seckill-order';


export interface SeckillOrderParam {
    seckillId?: number;
    page?: number; 
    size?: number;
    sort?: Array<string>;
}

export interface SeckillOrderResponse {
    id?: number;
    memberId: string;
    seckillId?: string;
    seckillItemId?: string;
    skuName?: string;
    skuPrice?: string;
    seckillPrice?: string;
    buyQuantity?: string;
    finalPayAmount?: string;
    status?: string;

    createdBy?: string;
    updatedBy?: string;
    createdAt?: string;
    updatedAt?: string;
}

export interface SeckillOrderSaveCommand {
    id?: number;
    memberId: string;
    seckillId?: string;
    seckillItemId?: string;
    skuName?: string;
    skuPrice?: string;
    seckillPrice?: string;
    buyQuantity?: string;
    finalPayAmount?: string;
    status?: string;
}

export interface SeckillOrderResponseList {
    list: SeckillOrderResponse[];
    total: number;
}


// 通过SeckillOrderParam参数获取分页列表
export function pageSeckillOrder(params: SeckillOrderParam) {
    return axios.get<SeckillOrderResponseList>(`${BASE_URL}/page`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    })
}

// 通过id获取秒杀订单信息
export function getSeckillOrder(id: number) {
    return axios.get<SeckillOrderResponse>(`${BASE_URL}/${id}`);
    
}

export function listSeckillOrder(params: SeckillOrderParam) {
    return axios.get<SeckillOrderResponse[]>(`${BASE_URL}/list`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    });
}


// 添加秒杀订单
export function addSeckillOrder(params: SeckillOrderSaveCommand) {
    return axios.post(`${BASE_URL}`, params);
}

// 更新秒杀订单
export function updateSeckillOrder(params: SeckillOrderSaveCommand) {
    return axios.put(`${BASE_URL}`, params);
}

// 批量删除秒杀订单
export function deleteSeckillOrder(ids: number | Array<number>) {
    return axios.delete(`${BASE_URL}/${ids}`);
}